//
//  MyCourseListViewModel.m
//  ForYourBeauty
//
//  Created by Kelly xu on 2019/7/18.
//  Copyright © 2019 changrenTech. All rights reserved.
//

#import "MyCourseListViewModel.h"

@implementation MyCourseListViewModel
-(void)fetchMyCourseList:(NSString*)year month:(NSString*)month cmp:(void(^)(NSArray *userUseDates,NSArray *hansImageDate,NSArray *menstruationDate))cmp{
    [[HttpClient shareClient]get:MY_COURSE_LIST params:@{@"year":year,@"month":month} suc:^(id results) {
        NSLog(@"_______________________________________%@",results);
        NSMutableArray *userDates = [[NSMutableArray alloc]init];
        [userDates addObjectsFromArray:[results objectForKey:@"userUseDate"]];
        NSMutableArray *hansImageDate = [[NSMutableArray alloc]init];
        [hansImageDate addObjectsFromArray:[results objectForKey:@"hansImageDate"]];
        NSMutableArray *menstruationDate = [[NSMutableArray alloc]init];
        [menstruationDate addObjectsFromArray:[results objectForKey:@"menstruationDate"]];
        cmp(userDates,hansImageDate,menstruationDate);
    } fail:^(NSString *error, NSInteger status) {
        Toast(error);
    }];
}
-(void)fetchUserDateList:(NSString*)date cmp:(void(^)(NSArray *userUseList))cmp{
    [[HttpClient shareClient]get:USER_USELIST params:@{@"date":date} suc:^(id results) {
        NSLog(@"_______________________________________%@",results);
        NSMutableArray *userUseList = [[NSMutableArray alloc]init];
        NSArray *array = [NSArray arrayWithArray:results];
        for (int i=0; i<[array count]; i++) {
            NSDictionary *dic = [array objectAtIndex:i];
            [userUseList addObject:[UserUseListModel modelObjectWithDictionary:dic]];
        }
        cmp(userUseList);
    } fail:^(NSString *error, NSInteger status) {
        Toast(error);
    }];
}
-(void)addCourse:(NSString*)courseId useFeel:(NSString*)useFeel usePicture:(NSString*)usePicture cmp:(void(^)())cmp{
    NSMutableDictionary *params = [[NSMutableDictionary alloc]initWithDictionary:@{@"id":courseId}];
    if (!EC_ISNullStr(useFeel)) {
        [params setObject:useFeel forKey:@"useFeel"];
    }
    if (!EC_ISNullStr(usePicture)) {
        [params setObject:usePicture forKey:@"usePicture"];
    }
    [[HttpClient shareClient]postWithUrl:USER_USE_ADD params:params suc:^(id results) {
        cmp();
    } fail:^(NSString *error, NSInteger status) {
        Toast(error);
    }];
}

-(void)fetchCourseImgs:(NSString*)year month:(NSString*)month cmp:(void(^)(NSArray *imgList))cmp{
    NSMutableDictionary *params = [[NSMutableDictionary alloc]initWithDictionary:@{@"year":year,@"month":month}];
    [[HttpClient shareClient]get:MY_COURSE_IMGS params:params suc:^(id results) {
        if ([results isKindOfClass:[NSArray class]]) {
            NSMutableArray *imgs = [[NSMutableArray alloc]init];
            for (int i=0; i<[results count]; i++) {
                NSDictionary *dic = [results objectAtIndex:i];
                [imgs addObject:[MyCourseImgModel modelObjectWithDictionary:dic]];
            }
            cmp(imgs);
        }
    } fail:^(NSString *error, NSInteger status) {
        Toast(error);
    }];
}
-(void)fetchFeelSelections:(void(^)(NSMutableArray *catList))cmp{
    [[HttpClient shareClient] get:SYSDIC params:@{@"dictType":@"SYGS"} suc:^(id results) {
        NSMutableArray *categoryList = [[NSMutableArray alloc]init];
        NSArray *catList = [NSArray arrayWithArray:results];
        for (int i=0;i<[catList count]; i++) {
            NSDictionary *dic = [catList objectAtIndex:i];
            [categoryList addObject:[SysDicModel modelObjectWithDictionary:dic]];
        }
        cmp(categoryList);
    } fail:^(NSString *error, NSInteger status) {
        Toast(error);
    }];
}
@end
